<template>
  <div class="sort-order-editor">
    <span>{{ value }}</span>
    <el-popover
      placement="top"
      v-model="popoverVisible"
      trigger="click"
      @show="handleShow"
    >
      <div class="flex-x justify-between gap-2">
        <el-input-number
          v-model="tempValue"
          :min="0"
          size="mini"
          controls-position="right">
        </el-input-number>
        <el-button size="mini" @click="popoverVisible = false">取消</el-button>
        <el-button type="primary" size="mini" @click="handleSubmit" class="ml-0">确定</el-button>
      </div>
      <el-button
        slot="reference"
        type="text"
        icon="el-icon-edit"
        style="margin-left: 5px">
      </el-button>
    </el-popover>
  </div>
</template>

<script>
export default {
  name: 'SortOrderEditor',
  props: {
    value: {
      type: Number,
      required: true
    }
  },
  data() {
    return {
      popoverVisible: false,
      tempValue: 0
    }
  },
  methods: {
    handleShow() {
      this.tempValue = this.value;
    },
    handleSubmit() {
      this.$emit('update', this.tempValue);
      this.popoverVisible = false;
    }
  }
}
</script>

<style scoped>
.sort-order-editor {
  display: inline-flex;
  align-items: center;
}
</style> 